home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / windownt / uupc11ys.zip / LIB / DOS2UNIX.C < prev    next >
C/C++ Source or Header  |  1993-04-10  |  4KB  |  125 lines

  1. /*--------------------------------------------------------------------*/
  2. /*      d o s 2 u n i x . c                                           */
  3. /*--------------------------------------------------------------------*/
  4.  
  5. /*--------------------------------------------------------------------*/
  6. /*    Changes Copyright (c) 1989 by Andrew H. Derbyshire.             */
  7. /*                                                                    */
  8. /*    Changes Copyright (c) 1990-1993 by Kendra Electronic            */
  9. /*    Wonderworks.                                                    */
  10. /*                                                                    */
  11. /*    All rights reserved except those explicitly granted by the      */
  12. /*    UUPC/extended license agreement.                                */
  13. /*--------------------------------------------------------------------*/
  14.  
  15. /*--------------------------------------------------------------------*/
  16. /*                          RCS Information                           */
  17. /*--------------------------------------------------------------------*/
  18.  
  19. /*
  20.  *    $Id: DOS2UNIX.C 1.4 1993/04/10 21:22:29 dmwatt Exp $
  21.  *
  22.  *    Revision history:
  23.  *    $Log: DOS2UNIX.C $
  24.  * Revision 1.4  1993/04/10  21:22:29  dmwatt
  25.  * Windows/NT fixes
  26.  *
  27.  * Revision 1.3  1993/04/05  12:26:01  ahd
  28.  * Correct headers to match gpkt
  29.  *
  30.  * Revision 1.2  1993/04/05  04:32:19  ahd
  31.  * Add timestamp, size to information returned by directory searches
  32.  *
  33.  * Revision 1.1  1993/04/04  19:35:14  ahd
  34.  * Initial revision
  35.  *
  36.  */
  37.  
  38. /*--------------------------------------------------------------------*/
  39. /*                        System include files                        */
  40. /*--------------------------------------------------------------------*/
  41.  
  42. #include <stdio.h>
  43. #include <time.h>
  44. #include <string.h>
  45.  
  46. /*--------------------------------------------------------------------*/
  47. /*                         OS/2 include files                         */
  48. /*--------------------------------------------------------------------*/
  49.  
  50. #ifdef FAMILY_API
  51. #define INCL_BASE
  52. #include <os2.h>
  53. #endif
  54.  
  55. /*--------------------------------------------------------------------*/
  56. /*                      Windows/NT include files                      */
  57. /*--------------------------------------------------------------------*/
  58.  
  59. #ifdef WIN32
  60. #include <windows.h>
  61. #endif
  62.  
  63. /*--------------------------------------------------------------------*/
  64. /*                    UUPC/extended include files                     */
  65. /*--------------------------------------------------------------------*/
  66.  
  67. #include "lib.h"
  68. #include "dos2unix.h"
  69.  
  70. /*--------------------------------------------------------------------*/
  71. /*       d o s 2 u n i x                                              */
  72. /*                                                                    */
  73. /*       Convert a DOS file time stamp to unix t_time                 */
  74. /*--------------------------------------------------------------------*/
  75.  
  76. time_t dos2unix( const FDATE ddmmyy,
  77.                  const FTIME ssmmhh )
  78. {
  79.  
  80.    struct tm  time_record;
  81.  
  82.    time_record.tm_sec = ssmmhh.twosecs * 2;
  83.    time_record.tm_min = ssmmhh.minutes;
  84.    time_record.tm_hour= ssmmhh.hours;
  85.  
  86.    time_record.tm_mday = ddmmyy.day;
  87.    time_record.tm_mon  = ddmmyy.month - 1;
  88.    time_record.tm_year = 80 + ddmmyy.year;
  89.  
  90.    time_record.tm_isdst = -1;
  91.  
  92.    return mktime(&time_record);
  93.  
  94. } /* dos2unix */
  95.  
  96. #ifdef WIN32
  97.  
  98. /*--------------------------------------------------------------------*/
  99. /*       n t 2 u n i x                                              */
  100. /*                                                                    */
  101. /*       Convert an NT file time stamp to unix t_time                 */
  102. /*--------------------------------------------------------------------*/
  103.  
  104. time_t nt2unix( FILETIME *nsec )
  105. {
  106.    SYSTEMTIME sysTime;
  107.    struct tm  time_record;
  108.  
  109.    FileTimeToSystemTime(nsec, &sysTime);
  110.  
  111.    time_record.tm_sec = sysTime.wSecond;
  112.    time_record.tm_min = sysTime.wMinute;
  113.    time_record.tm_hour= sysTime.wHour;
  114.  
  115.    time_record.tm_mday = sysTime.wDay;
  116.    time_record.tm_mon  = sysTime.wMonth - 1;
  117.    time_record.tm_year = sysTime.wYear - 1900;
  118.  
  119.    time_record.tm_isdst = -1;
  120.  
  121.    return mktime(&time_record);
  122.  
  123. } /* nt2unix */
  124. #endif
  125.